<!--
	Copyright (C) 2010 Ethan Gruber
	EADitor: http://code.google.com/p/eaditor/
	Apache License 2.0: http://code.google.com/p/eaditor/
	
	Delete selected EAD guide from eXist (or other interface).  This is linked from the file list page -->
<html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms"
	xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xi="http://www.w3.org/2001/XInclude">
	<head>
		<title>EADitor: Publish</title>
		<link type="text/css" href="http://localhost:8080/cocoon/numishare/xforms.css"
			rel="stylesheet"/>
		<xforms:model>
			<xforms:instance id="id">
				<!-- Start with placeholders for three files -->
				<id xmlns=""/>
			</xforms:instance>

			<xforms:instance id="site-info">
				<site_info xmlns="">
					<title/>
					<pages>
						<page stub="" id="">
							<title/>
							<short-title/>
							<public/>
							<text/>
						</page>
					</pages>
				</site_info>
			</xforms:instance>

			<xforms:instance id="status">
				<status/>
			</xforms:instance>

			<xforms:instance id="to-publish">
				<verification xmlns="">Click OK to publish <title/>.</verification>
			</xforms:instance>

			<xforms:instance id="unpublish">
				<verification xmlns="">Click OK to unpublish <title/>.</verification>
			</xforms:instance>

			<!-- get id parameter and set that to be the file to create or delete -->
			<xforms:action ev:event="xforms-model-construct-done">
				<xforms:setvalue ref="instance('id')" value="xxforms:get-request-parameter('id')"/>
				<xforms:setvalue ref="instance('verification')/title"
					value="xxforms:get-request-parameter('title')"/>
				<xforms:send submission="load-submission"/>
			</xforms:action>

			<!-- publish or unpublish depending on mode attribute -->
			<xforms:action ev:event="xforms-ready">
				<xxforms:variable name="mode" select="xxforms:get-request-parameter('mode')"/>

				<xforms:action if="$mode = 'create'">
					<xforms:setvalue ref="instance('to-publish')/title"
						value="xxforms:get-request-parameter('title')"/>
				</xforms:action>
				<xforms:action if="$mode = 'delete'">
					<xforms:setvalue ref="instance('unpublish')/title"
						value="xxforms:get-request-parameter('title')"/>
					<xforms:toggle case="remove-publication-verification"
						ev:event="xforms-model-construct-done"/>
				</xforms:action>
			</xforms:action>

			<xforms:submission id="load-submission" serialization="none" method="get"
				action="/exist/rest/db/numishare/site_info.xml" xxforms:username="admin"
				xxforms:password="admin" replace="instance" instance="site-info"/>

			<xforms:submission id="save-submission" ref="instance('site-info')"
				xxforms:username="admin" xxforms:password="admin"
				action="/exist/rest/db/numishare/site_info.xml" method="put" replace="none">
				<xforms:toggle case="status-update" ev:event="xforms-submit-done"/>
				<xforms:message ev:event="xforms-submit-error" level="modal">Error saving
					file!</xforms:message>
			</xforms:submission>
		</xforms:model>
	</head>
	<body>
		<div class="form">
			<!-- publish or unpublish depending on mode attribute -->
			<xforms:switch>
				<xforms:case id="publication-verification">
					<p>
						<xforms:output ref="instance('to-publish')"/>
					</p>

					<xforms:trigger appearance="full">
						<xforms:label class="file_control">OK</xforms:label>
						<xforms:action ev:event="DOMActivate">
							<xforms:setvalue
								ref="instance('site-info')//page[@id=instance('id')]/public"
								value="1"/>
							<xforms:setvalue ref="instance('status')">Page
								published.</xforms:setvalue>
							<xforms:send submission="save-submission"/>
						</xforms:action>
					</xforms:trigger>
				</xforms:case>
				<xforms:case id="remove-publication-verification">
					<p>
						<xforms:output ref="instance('unpublish')"/>
					</p>
					<xforms:trigger appearance="full">
						<xforms:label class="file_control">OK</xforms:label>
						<xforms:action ev:event="DOMActivate">
							<xforms:setvalue
								ref="instance('site-info')//page[@id=instance('id')]/public"
								value="0"/>
							<xforms:setvalue ref="instance('status')">Page
								unpublished.</xforms:setvalue>
							<xforms:send submission="save-submission"/>
						</xforms:action>
					</xforms:trigger>
				</xforms:case>
				<xforms:case id="status-update">
					<xforms:group ref="instance('status')/text()">
						<div class="success">
							<xforms:output ref="instance('status')"/>
						</div>
					</xforms:group>
				</xforms:case>
			</xforms:switch>
		</div>
		<!--<widget:xforms-instance-inspector id="orbeon-xforms-inspector"
			xmlns:widget="http://orbeon.org/oxf/xml/widget"/>-->
	</body>
</html>
